package com.saileijieji.mymvp.view.main;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationData;
import com.saileijieji.mylibrary.android.TopBar;
import com.saileijieji.mymvp.R;
import com.saileijieji.mymvp.WlApplication;
import com.saileijieji.mymvp.mvp.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @describe: fire-control-android
 * @author: 武梁
 * @date: 2018/8/6 11:50
 * @mailbox: 1034905058@qq.com
 */
public class MainNavigationpageActivity extends BaseActivity {
    @Bind(R.id.mTopBar)
    TopBar mTopBar;
    @Bind(R.id.main_map)
    MapView mainMap;
    @Bind(R.id.main_lay_renwu)
    LinearLayout mainLayRenwu;
    @Bind(R.id.main_lay_shangchuan)
    LinearLayout mainLayShangchuan;
    @Bind(R.id.main_lay_baobiao)
    LinearLayout mainLayBaobiao;
    @Bind(R.id.main_quyu)
    LinearLayout mainQuyu;
    BaiduMap mBaiduMap;
    BitmapDescriptor mCurrentMarker;
    MyLocationConfiguration.LocationMode mCurrentMode;
    int accuracyCircleFillColor,accuracyCircleStrokeColor;
    private MyLocationListener myListener = new MyLocationListener();
    public LocationClient mLocationClient = null;
    @Override
    public void showData(int tag, Object data) {

    }

    public class MyLocationListener extends BDAbstractLocationListener {
        @Override
        public void onReceiveLocation(BDLocation location){
            //此处的BDLocation为定位结果信息类，通过它的各种get方法可获取定位相关的全部结果
            //以下只列举部分获取经纬度相关（常用）的结果信息
            //更多结果信息获取说明，请参照类参考中BDLocation类中的说明
            MyLocationData locData = new MyLocationData.Builder()
                    .accuracy(location.getRadius())
                    // 此处设置开发者获取到的方向信息，顺时针0-360
                    .direction(100).latitude(location.getLatitude())
                    .longitude(location.getLongitude()).build();

// 设置定位数据
            mBaiduMap.setMyLocationData(locData);
        }
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mainnavigtion);
        ButterKnife.bind(this);
        mBaiduMap = mainMap.getMap();
        mCurrentMarker = BitmapDescriptorFactory.fromResource(R.drawable.iconzuobiao);
//        mCurrentMode = MyLocationConfiguration.LocationMode.FOLLOWING;//定位跟随态
        mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;   //默认为 LocationMode.NORMAL 普通态
//        mCurrentMode = MyLocationConfiguration.LocationMode.COMPASS;  //定位罗盘态
        accuracyCircleFillColor = 0xAAFFFF88;//自定义精度圈填充颜色
        accuracyCircleStrokeColor = 0xAA00FF00;//自定义精度圈边框颜色
        mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
                mCurrentMode, true, mCurrentMarker,
                accuracyCircleFillColor, accuracyCircleStrokeColor));
        // 开启定位图层
        mBaiduMap.setMyLocationEnabled(true);

        SDKInitializer.initialize(getApplicationContext());
        mLocationClient = new LocationClient(getApplicationContext());
        //声明LocationClient类
        mLocationClient.registerLocationListener(myListener);
        //注册监听函数
        LocationClientOption option = new LocationClientOption();

        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        option.setCoorType("bd09ll");
        option.setScanSpan(1000);
        option.setOpenGps(true);
        option.setLocationNotify(true);
        option.setIgnoreKillProcess(false);
        option.SetIgnoreCacheException(false);

        option.setWifiCacheTimeOut(5*60*1000);

        option.setEnableSimulateGps(false);

        mLocationClient.setLocOption(option);

        mLocationClient.start();
    }

    @OnClick({R.id.main_lay_renwu, R.id.main_lay_shangchuan, R.id.main_lay_baobiao, R.id.main_quyu})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.main_lay_renwu:
                break;
            case R.id.main_lay_shangchuan:
                startActivity(new Intent(this,PollingUploadingActivity.class));
                break;
            case R.id.main_lay_baobiao:
                break;
            case R.id.main_quyu:

                break;
                default:
        }
    }
}
